package jun.cli;

import java.util.Calendar;

import jun.comm.netkit.JunClient;
import jun.comm.netkit.JunProtocol;

public class UserCli extends JunClient{


	public static void main(String[] args) throws Exception {

//		UserCli cli = new UserCli();
//		cli.init("127.0.0.1", 50080);
//		cli.run();
		
		Calendar cal = Calendar.getInstance();
		for(int i=0;i<1000;i++){
			UserCli cli = new UserCli();
			cli.init("127.0.0.1", 50080);
			cli.run("这里是客户端发送的数据"+i);
			System.out.println(i);
		}
		System.out.println(Calendar.getInstance().getTimeInMillis()-cal.getTimeInMillis());
	}
	
	public void init(String ip, int port) throws Exception{
		super.init(ip, port);
	}
	
	public void run(String cont){
		int rt = 0;
		
		// 创建传输的协议
		JunProtocol sendProtocol = new JunProtocol();
		sendProtocol.cont = cont;
		rt = send(sendProtocol);
		if(rt!=0){
			System.out.println("send err; rt="+rt);
		}
		
		JunProtocol recvProtocol = new JunProtocol();
		rt = recv(recvProtocol);
		if(rt!=0){
			System.out.println("recv err; rt="+rt);
		}
	}
	
	public void run1(){
		int rt = 0;
		
		// 创建传输的协议
		JunProtocol sendProtocol = new JunProtocol();
		sendProtocol.cont = "111111111111111111111111";
		rt = send(sendProtocol);
		if(rt!=0){
			System.out.println("send err; rt="+rt);
		}
		
		JunProtocol recvProtocol = new JunProtocol();
		rt = recv(recvProtocol);
		if(rt!=0){
			System.out.println("recv err; rt="+rt);
		}
	}

}
